/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.account.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.account.domain.AccountAc08;
import me.zhengjie.modules.account.domain.dto.AccountAa03QueryCriteria;
import me.zhengjie.modules.account.domain.dto.AccountAc08QueryCriteria;
import me.zhengjie.modules.account.service.AccountAc43Service;
import me.zhengjie.modules.basic.domain.BasicAb01;
import me.zhengjie.modules.transfer.service.TransferOutService;
import me.zhengjie.tool.MyMap;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* @author ly
* @date 2025-04-23
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "api")
@RequestMapping("/api/accountAc43")
public class AccountAc43Controller {

    private final AccountAc43Service accountAc43Service;
    private final TransferOutService transferOutService;

    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('accountAa03:list')")
    public void exportAccountAa03(HttpServletResponse response, AccountAa03QueryCriteria criteria) throws IOException {
//        accountAc43Service.download(accountAc43Service.queryAll(criteria), response);
        MyMap<Object, Object> map = new MyMap<>();
        map.put("aac001","53332310398475");
        map.put("aab359","533323");
        map.put("aaz159","53000000000031086246");
        map.put("aae140","120");
        map.put("aae041","201410");

//        accountService.saveInterest(map);
        transferOutService.transferOutPreview(map);
    }

    @GetMapping("/getPersonFrees")
    @ApiOperation("查询人员缴费明细")
    public ResponseEntity<PageResult<AccountAc08>> getPersonFrees(AccountAc08QueryCriteria criteria){
        Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String, Object> param = objectMapper.convertValue(criteria, Map.class);
        return new ResponseEntity<>(accountAc43Service.queryAll(param,page),HttpStatus.OK);
    }

    @PostMapping("/save")
    @ApiOperation("单位人员退费")
    public ResponseEntity<Object> save(@RequestBody Map resources) throws Exception {
        accountAc43Service.save(new MyMap(resources));
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

}
